//
//  BSVideoCell.m
//  BS
//
//  Created by lanou on 15/8/17.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "BSVideoCell.h"

#import "Header.h"

#import "UIImageView+WebCache.h"

#import "UILabel+LJLabel.h"

#import "PlayerManger.h"

@implementation BSVideoCell


- (void)setModel:(BSListModel *)model{
    
    _model = model;
    _contentLabel.text = _model.text;
    _videoTimeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld", [model.videotime integerValue] / 60, [model.videotime integerValue] % 60];
    _playCountLabel.text = [NSString stringWithFormat:@"%@播放",_model.playcount];
    //自定义行间距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:model.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:5];//调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [model.text length])];
    _contentLabel.attributedText = attributedString;
    [_contentLabel sizeToFit];
    [_imaView sd_setImageWithURL:[NSURL URLWithString:model.cdn_img]];
}


- (IBAction)play:(UIButton *)sender {
    
    //将当前正在播放的indexPath传给播放器
    NSLog(@"播放视频");
    PlayerManger *manager = [PlayerManger defaultManger];
    [manager stop];
    UITableView *tableView = (UITableView *)self.superview.superview;
    NSIndexPath *indexPath = [tableView indexPathForCell:self];
    manager.currentModel = _model;
    manager.indexPath = indexPath;
    [manager playWithURL:_model.videouri frame:self.imaView.frame mediaType:Vedio];
    [self.contentView addSubview:manager.view];
}

+ (CGFloat)heightOfCell:(BSListModel *)model{
    
    if (model.cellHeight == 0){
        model.cellHeight = [UILabel heightOfLabelByStr:model.text fontSize:17 width:SCREEN_WIDTH - 2 * 8 lineSpacing:5] + 16 + (SCREEN_WIDTH / [model.width floatValue] * [model.height floatValue]);
    }
      return model.cellHeight;
}

- (void)awakeFromNib {

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
